﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartSpace.Core;

namespace SmartSpace.Orgs
{
    public partial class OrgsService : IOrgsService
    {
        public ServiceResult AssignPost(Guid employeeId, Guid orgId, bool isMajor)
        {
            using (OrgsDbContext context = new OrgsDbContext())
            {
                EmployeePost ePost = new EmployeePost();
                ePost.EmployeeId = employeeId;
                ePost.OrgId = orgId;
                ePost.IsMajor = isMajor;
                context.EmployeePostSet.Add(ePost);

                return new ServiceResult(EntityRepository.Commit(context));
            }
        }

        public List<EmployeePost> GetPosts(Guid employeeId)
        {
            using (OrgsDbContext context = new OrgsDbContext())
            {
                return context.EmployeePostSet.Where(p => p.EmployeeId == employeeId).ToList();
            }
        }

        public EmployeePost GetMajorPost(Guid employeeId)
        {
            using (OrgsDbContext context = new OrgsDbContext())
            {
                return context.EmployeePostSet.Where(p => p.EmployeeId == employeeId && p.IsMajor).SingleOrDefault();
            }
        }
    }
}
